package com.sneakxy.cloudbase.platform.bean.dto;

import java.util.ArrayList;
import java.util.List;

import javax.validation.constraints.NotBlank;

import org.springframework.beans.BeanUtils;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.sneakxy.cloudbase.platform.bean.UploadFile;
import com.sneakxy.cloudbase.platform.bean.ValidAdd;
import com.sneakxy.cloudbase.platform.bean.ValidEdit;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 上传文件信息DTO
 * @author 潜行的虚影
 * @see
 */
@Data
@ApiModel("上传文件信息")
@EqualsAndHashCode
@JsonIgnoreProperties(ignoreUnknown = true)
public class UploadFileDTO implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4017184766415233359L;

	public final static String TYPE_FTP = "ftp";
	
	public final static String TYPE_FASTDFS = "fastdfs";
	
	public final static String TYPE_LOCAL = "local";
	
	public final static String EXTENT_PUBLIC = "0";
	
	public final static String EXTENT_PRIVATE = "1";
	
	public final static String FILETYPE_NORMAL = "0";

	@NotBlank(groups = ValidEdit.class)
	@ApiModelProperty("主键ID")
	private String id;

	@ApiModelProperty("文件名")
	private String name;

	@ApiModelProperty("文件存储路径")
	private String path;

	@ApiModelProperty("文件存储类型：fdfs、local、ftp")
	private String storetype;

	@ApiModelProperty("文件类型")
	private String contentType;

	@ApiModelProperty("")
	private Long size;

	@NotBlank(groups = {ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("使用范围：0、公共，1、私人")
	private String extent;

	@ApiModelProperty("文件种类：0、普通文件")
	private String filetype;

	@ApiModelProperty("拥有者ID：account_id")
	private String owner;

	@ApiModelProperty("下载次数")
	private Long downloads;

	@ApiModelProperty("上传时间")
	private String uploadtime;

	public static UploadFileDTO from(UploadFile entity) {
		UploadFileDTO result = new UploadFileDTO();
		BeanUtils.copyProperties(entity, result);
		return result;
	}
	
	public static List<UploadFileDTO> from(Iterable<UploadFile> list) {
		List<UploadFileDTO> result = new ArrayList<>();
		list.forEach(entity -> {
			result.add(from(entity));
		});
		return result;
	}
	
	public static UploadFile to(UploadFileDTO entity) {
		UploadFile result = new UploadFile();
		BeanUtils.copyProperties(entity, result);
		return result;
	}
	
	public static List<UploadFile> to(List<UploadFileDTO> list) {
		List<UploadFile> result = new ArrayList<>(list.size());
		list.forEach(entity -> {
			result.add(to(entity));
		});
		return result;
	}

}
